package vip.xiaonuo.modular.devicemegvii.controller;

import com.joe.util.GsonUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import vip.xiaonuo.core.annotion.BusinessLog;
import vip.xiaonuo.core.annotion.Permission;
import vip.xiaonuo.core.enums.LogAnnotionOpTypeEnum;
import vip.xiaonuo.core.pojo.response.ResponseData;
import vip.xiaonuo.facedoor.modular.memberuser.entity.MemberUser;
import vip.xiaonuo.facedoor.modular.memberuser.param.MemberUserParam;
import vip.xiaonuo.facedoor.modular.memberuser.service.FacedoorMemberUserService;
import vip.xiaonuo.facedoor.modular.memberuser.service.MemberUserService;
import vip.xiaonuo.megvii.faces.model.FaceDelete;
import vip.xiaonuo.megvii.service.DeviceMegviiConfigService;
import vip.xiaonuo.megvii.service.DeviceMegviiFaceService;
import vip.xiaonuo.modular.devicemegvii.entity.DeviceMegvii;
import vip.xiaonuo.modular.devicemegvii.param.DeviceMegviiParam;
import vip.xiaonuo.modular.devicemegvii.service.DeviceMegviiService;

import javax.annotation.Resource;


/**
 * 与AI设备直接通信的控制器
 */
@RestController
@Slf4j
public class DeviceMegviiDirectController {

    @Resource
    private DeviceMegviiService deviceMegviiService;

    @Resource
    private FacedoorMemberUserService memberUserService;

    @Resource
    private DeviceMegviiConfigService configService;

    @Resource
    private DeviceMegviiFaceService faceService;


    /**
     * AI智能分析盒检查参数
     *
     * @author 朱华波
     * @date 2022-09-13 15:46:17
     * @return
     */
    @Permission
    @PostMapping("/deviceMegvii/check")
    @BusinessLog(title = "AI智能分析盒_检查参数", opType = LogAnnotionOpTypeEnum.CHANGE_STATUS)
    public ResponseData check(@RequestBody DeviceMegviiParam deviceMegviiParam) {
        DeviceMegvii device = deviceMegviiService.detail(deviceMegviiParam);
        return configService.check(device,true);
    }

    /**
     * 人脸入库
     * @param memberUserParam
     * @return
     */
    @Permission
    @PostMapping("/deviceMegvii/faces/instore")
    @BusinessLog(title = "AI智能分析盒_人脸入库", opType = LogAnnotionOpTypeEnum.CHANGE_STATUS)
    public ResponseData faceInStore(@RequestBody MemberUserParam memberUserParam) {
        MemberUser user = memberUserService.detail(memberUserParam);
        return faceService.faceInStore(user);
    }

    /**
     * 人脸删除
     * @param faceDelete (特征值表 + 删除模式)
     * @return
     */
    @Permission
    @PostMapping("/deviceMegvii/faces/delete")
    @BusinessLog(title = "AI智能分析盒_人脸入库", opType = LogAnnotionOpTypeEnum.CHANGE_STATUS)
    public ResponseData faceDelete(@RequestBody FaceDelete faceDelete) {
        log.info("人脸删除接收到的数据：{}" , GsonUtils.objToJson(faceDelete));
        return faceService.faceDelete(faceDelete);
    }




}
